# dictionary_model.py

from src import db

from .base_model import BaseModel


class Dictionary(BaseModel):
    __tablename__ = "dictionary"
    __table_args__ = (
        db.Index("uk_dict_type_label", "dict_type", "dict_label"),
        {"extend_existing": True},
    )

    dict_type = db.Column(db.String(64), nullable=False, index=True, info={"description": "字典类型"})
    dict_label = db.Column(db.String(128), nullable=False, info={"description": "字典标签"})
    dict_value = db.Column(db.String(128), nullable=False, info={"description": "字典值"})
    remarks = db.Column(db.String(255), info={"description": "备注"})
    extras = db.Column(db.JSON, info={"description": "额外属性"})

    def to_dict(self):
        """自定义转字典格式方法"""
        return {
            "id": self.id,
            "dict_type": self.dict_type,
            "dict_label": self.dict_label,
            "dict_value": self.dict_value,
            # "status": self.status,
            # "remarks": self.remarks,
            "extras": self.extras,
            # "gmt_create": self.gmt_create.strftime("%Y-%m-%d %H:%M:%S") if self.gmt_create else None,
            # "gmt_modified": self.gmt_modified.strftime("%Y-%m-%d %H:%M:%S") if self.gmt_modified else None,
        }
